
function getParam(paramName) {
    var paramValue = "",
        isFound = !1;
    var index=this.location.href.lastIndexOf("?");
    var obj=this.location.href.substring(index,this.location.href.length);

    if (obj.indexOf("?") == 0 && obj.indexOf("=") > 1) {
        arrSource = unescape(obj).substring(1, obj.length).split("&"),
            i = 0;
        while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0),
            i++
    }
    return paramValue == "" && (paramValue = null),
        paramValue
}
/// <reference path="app.js" />
angular.module('businessApp', ['ui.bootstrap', 'ui.load', 'ui.jq', 'ionic', 'starter.services', 'starter.directives', 'ngCordova', 'ion-datetime-picker'])
    .run(function ($ionicPlatform, $location, $timeout, $rootScope,
                   $ionicHistory, $state, $ionicPickerI18n) {
        //时间控件自定义设定
        var lang = window.localStorage.getItem('H3.Language') || 'zh_cn';
        if (lang == 'en_us') {
            $ionicPickerI18n.weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
            $ionicPickerI18n.months = ["Jan", "Fed", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Otc", "Nov", "Dec"];
            $ionicPickerI18n.ok = "OK";
            $ionicPickerI18n.cancel = "Clear";
            $ionicPickerI18n.okClass = "button-balanced";
            // $ionicPickerI18n.cancelClass = "button-balanced";
        } else {
            $ionicPickerI18n.weekdays = ["日", "一", "二", "三", "四", "五", "六"];
            $ionicPickerI18n.months = ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"];
            $ionicPickerI18n.ok = "确定";
            $ionicPickerI18n.cancel = "取消";
            $ionicPickerI18n.okClass = "button-balanced";
            // $ionicPickerI18n.cancelClass = "button-balanced";
        }

        //添加事件监听
        $rootScope.$on("$stateChangeStart", function (e, ts, tp, fs, ft) {
            if (fs.name.indexOf("app.") != -1) {
                $("[name='app-view']").find("ion-view").attr("nav-view", "cached");
            }
        });
    }).controller('MyCtrl', function($scope) {
    $scope.sub={clientData:""};
    $scope.data = {
        showDelete: false,
        showReorder:false
    };

    $scope.edit = function(item) {
       location.href="/Portal/MvcDefaultSheet.jsp?BizObjectID="+item.objectId +"&IsMobile=true&SchemaCode=businessOpportunity&SheetCode=SbusinessOpportunity&Mode=Work"
    };
    $scope.share = function(item) {
        alert('Share Item: ' + item.id);
    };


    $scope.state =   getParam("state");
    $.ajax({
             type:"get",
             async: false,
             url:"/Portal/CRM/BusinessOpportunity/getBoList?start=0&state="+$scope.state,
             success:function(data){

                   if(data.status!="500"){
                       $scope.items = data.data;
                   }else{
                       alert("系统异常");
                   }
             }
         })


    $scope.skipAdd= function(){
        var  Version="";
        $.ajax({
            type:"POST",
            async: false,
            url:"/Portal/WorkflowTemplateSetting/Load?WorkflowCode=businessOpportunity",
            success:function(data){
                if(data.status!="500"){
                    Version = data.WorkflowVersions[data.WorkflowVersions.length-1].Value;
                }else{
                    alert("系统异常");
                }
            }
        })
        if(Version==""||Version==undefined){
            Version="1";
        }

        location.href="http://www.kumhosunny.cn:8099/Portal/MvcDefaultSheet.jsp?SheetCode=SbusinessOpportunity&Mode=Originate&WorkflowCode=businessOpportunity&SheetCode=&WorkflowVersion="+Version+"&IsMobile=true#/form/detail";
    }

    $scope.clearContent= function () {

        $scope.sub.clientData="";
        $scope.searchAndrefresh();
    }
    $scope.searchAndrefresh = function () {

        $.ajax({
            type:"get",
            async: false,
            url:"/Portal/CRM/BusinessOpportunity/getBoList?start=0&state="+$scope.state+"&clientData="+$scope.sub.clientData,
            success:function(data){

                if(data.status!="500"){
                    $scope.items = data.data;
                }else{
                    alert("系统异常");
                }
            }
        })

    }

    $scope.addItems=function(){
        $scope.state =   getParam("state");
        var  item = $scope.items;

            $.ajax({
                type: "get",
                async: false,
                url: "/Portal/CRM/BusinessOpportunity/getBoList?start=" + $scope.items.length + "&state=" + $scope.state + "&clientData=" + $scope.sub.clientData,
                success: function (data) {
                    if (data.status != "500") {

                        for (var i = 0; i < data.data.length; i++) {
                            $scope.items.push(data.data[i]);
                        }
                        $scope.$broadcast('scroll.infiniteScrollComplete');
                    } else {
                        alert("系统异常");
                    }
                }
            })


    }


    $scope.GoBack = function () {
        window.history.back();
    }


})
    .config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {

        $ionicConfigProvider.platform.ios.tabs.style('standard');
        $ionicConfigProvider.platform.ios.tabs.position('bottom');
        $ionicConfigProvider.platform.android.tabs.style('standard');
        $ionicConfigProvider.platform.android.tabs.position('standard');

        //安卓手机不能滑动的bug
        $ionicConfigProvider.scrolling.jsScrolling(true);


        $ionicConfigProvider.platform.ios.navBar.alignTitle('center');
        /*   $ionicConfigProvider.platform.android.navBar.alignTitle('left');*/

        $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left');
        $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back');

        $ionicConfigProvider.platform.ios.views.transition('ios');
        $ionicConfigProvider.platform.android.views.transition('android');

      //  var defaultState = "/tab/home";
    /*    if (window.cordova) {
            defaultState = "/login";
            // defaultState = "/tab/home";
        }*/
        // Ionic uses AngularUI Router which uses the concept of states
        // Learn more here: https://github.com/angular-ui/ui-router
        // Set up the various states which the app can be in.
        // Each state's controller can be found in controllers.js
        $stateProvider

        // setup an abstract state for the tabs directive

        ////表单页-编辑-展示
        //.state('inputGroup', {
        //    url: '/inputGroup',
        //    templateUrl: 'templates/input-group.html',
        //    controller: 'inputGroupCtrl'
        //})
        ////流程详情
        //.state('details', {
        //    url: '/details',
        //    templateUrl: 'templates/details.html',
        //    controller: 'detailsCtrl'
        //})
        ////普通流程详情
        //.state('listDetails', {
        //    url: '/listDetails',
        //    templateUrl: 'templates/listDetails.html',
        //    controller: 'listDetailsCtrl'
        //})
        //$urlRouterProvider.otherwise(defaultState);
    });


